home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS16.ADF / C / ShowPrint / ShowPrint.c < prev    next >
C/C++ Source or Header  |  1989-01-27  |  7KB  |  277 lines

  1. /********************************************************************
  2. *        ShowAll - v1.2    (formerly Plop)                *
  3. *********************************************************************
  4. This is a Public Domain Property, so feel free to copy, to modified,
  5. etc as long as it is not for commercial use and this notice is intact
  6.  
  7. Original Author : Jim Kent      (April   86)
  8. V1.1        : Andry Rachmat (October 86)
  9. V1.2        : Brian Conrad  (November 86)
  10. *********************************************************************
  11.  
  12. V1.1 Modification:
  13.     Add Window and Close Window Gadget, remove 2 seconds timer
  14.     Recover memory on OpenScreen failure
  15.     Clean up the code to compile cleanly on Aztec C
  16.  
  17. Bugs:
  18.     Argc loop seems not working for unknown reason
  19.     On 1.1 Workbench Close Window Gadget will shown on the top left
  20.     corner (I don't how to hide the window).
  21.     MAJOR BUGS on 1.1 is the OpenScreen failure (mostly due to
  22.     insufficient memory available to open hires screen) will recover
  23.     99% of memory used, but it CRASHES the next time you run the
  24.     program! (Works fine on 1.2 Workbench)
  25.  
  26. *********************************************************************
  27.  
  28. V1.2 Modification:
  29.     Window Closes on MOUSEBUTTONS instead of CLOSEWINDOW
  30.     No need to move pointer to Close Window Gadget
  31.  
  32. *********************************************************************/
  33. #ifdef LATER
  34. #define DEBUG
  35. #endif LATER
  36. #define PARANOID
  37.  
  38. #include    <exec/types.h>
  39. #include     <exec/nodes.h>
  40. #include    <exec/libraries.h>
  41. #include    <graphics/gfx.h>
  42. #include    <graphics/rastport.h>
  43. #include    <graphics/text.h>
  44. #include     <graphics/view.h>
  45. #include    <intuition/intuition.h>
  46. #include     <stdio.h>
  47. #include     "jiff.h"
  48.  
  49.  
  50.  
  51.  
  52. /*This should be in exec/libraries.h */
  53. extern struct Library *OpenLibrary();
  54.  
  55. /*This should be in intuition/intuition.h */
  56. extern struct Screen *OpenScreen();
  57.  
  58. extern struct Window *OpenWindow();
  59. extern struct IntuiMessage *GetMsg();
  60.  
  61. /* These are the bases for the libraries you need to do any graphics
  62.    much at all and still multi-task */
  63. struct Library *GfxBase = NULL;
  64. struct Library *LayersBase = NULL;
  65. struct Library    *IntuitionBase = NULL;
  66. struct IntuiMessage *message;
  67.  
  68. /* Well the workbench Screen isn't 320x200x5 so...*/
  69. struct Screen *PlopScreen = NULL;
  70. struct Window *window = NULL;
  71.  
  72. /* Just one font for me... not static cause you might want it
  73.    in your menu modules. */
  74. struct TextAttr PlopFont =
  75.     {
  76.     (UBYTE *) "topaz.font",  /* I think this is the ROM font */
  77.     8,
  78.     0,
  79.     0,
  80.     };
  81.  
  82. /* a NewScreen - I don't know what half of this means either */
  83. static
  84. struct NewScreen PlopNewScreen =
  85.     {
  86.     0, 0, XMAX, YMAX, PLANES,
  87.     0, 1,
  88.     0,
  89.     CUSTOMSCREEN,
  90.     &PlopFont,
  91.     (UBYTE *) "",
  92.     NULL,
  93.     NULL,
  94.     };
  95.  
  96. static
  97. struct NewWindow MyWindow =
  98.     {
  99.     0,0,14,10,
  100.     0,1,
  101.     CLOSEWINDOW|RAWKEY| MOUSEBUTTONS | MOUSEMOVE |SELECTUP,
  102.     SMART_REFRESH|ACTIVATE |RMBTRAP| WINDOWCLOSE | REPORTMOUSE | BORDERLESS,
  103.     NULL,
  104.     NULL,
  105.     (UBYTE *) "",
  106.     NULL,
  107.     NULL,
  108.     14,10,14,10,
  109.     CUSTOMSCREEN,
  110.     };
  111.     
  112. struct RastPort PlopRastPort;
  113.  
  114. /*put_ea_cmap given an ea-type color map:
  115.         an array of unsigned chars of form ea_cmap[] = {r, g, b, r, g, b...}
  116.   turn it into an amiga-type color map:
  117.           an array of unsigned short of form amiga_cmap = {0xrgb, 0xrgb, ...}
  118.   and then tell Dale this is the colors we want for our viewport */
  119. void
  120. put_ea_cmap(cmap, colors)
  121. unsigned char *cmap;
  122. int colors;
  123. {
  124. unsigned short amy_cmap[MAXCOL];
  125. int i;
  126. unsigned char r, g, b;
  127.  
  128. if (colors > MAXCOL)    /*color clipping*/
  129.     colors = MAXCOL;
  130. for (i=0; i<colors; i++)
  131.     {
  132.     amy_cmap[i] = 
  133.         ((*cmap++ & 0xf0) << 4) + (*cmap++ & 0xf0) + ((*cmap++ & 0xf0) >> 4);
  134.     }
  135. LoadRGB4( &PlopScreen->ViewPort, amy_cmap, (long)colors);
  136. }
  137.  
  138. /* back out backwards */
  139. void
  140. plop_cleanup()
  141. {
  142. if (PlopScreen != NULL)
  143.     CloseScreen(PlopScreen);
  144. if (IntuitionBase != NULL)
  145.     CloseLibrary(IntuitionBase);
  146. if (LayersBase != NULL)
  147.     CloseLibrary(LayersBase);
  148. if (GfxBase != NULL)
  149.     CloseLibrary(GfxBase);
  150. }
  151.  
  152.  
  153. main(argc, argv)
  154. int argc;
  155. char *argv[];
  156. {
  157. int i, class,code;
  158. struct ILBM_info *info=NULL;
  159.  
  160. if ((argc==1) || (argv[1][0]=='?'))
  161.     {printf("Usage : ShowPrint filename\n\n");
  162.      return(0);}
  163.  
  164. /*Before we can do ANYTHING have to get our libraries... */
  165. if ((GfxBase =  OpenLibrary("graphics.library", (long)0)) == NULL)
  166.     {
  167. #ifdef PARANOID
  168.     printf("Can't open Graphics Library\n");
  169. #endif PARANOID
  170.     return(-1);
  171.     }
  172.  
  173. if ((LayersBase =  OpenLibrary("layers.library", (long)0)) == NULL)
  174.     {
  175. #ifdef PARANOID
  176.     printf("Can't open Layers Library\n");
  177. #endif PARANOID
  178.     plop_cleanup();
  179.     return(-2);
  180.     }
  181.  
  182. /* Two for Dale and one for RJ */
  183. if ((IntuitionBase =  OpenLibrary("intuition.library",(long) 0)) == NULL)
  184.     {
  185. #ifdef PARANOID
  186.     printf("Can't open Intuition Library\n");
  187. #endif PARANOID
  188.     plop_cleanup();
  189.     return(-3);
  190.     }
  191.  
  192. for (i=1; i<argc; i++)
  193.     {
  194. #ifdef DEBUG
  195.     puts(argv[i]);
  196. #endif DEBUG
  197.     if ( (info = read_iff(argv[i], 0) ) != NULL)
  198.         {
  199.         if (PlopScreen != NULL)
  200.             CloseScreen(PlopScreen);
  201.                 PlopScreen = NULL;
  202.         PlopNewScreen.LeftEdge = info->header.x;
  203.         PlopNewScreen.TopEdge = info->header.y;
  204.         PlopNewScreen.Width = info->header.w;
  205.         PlopNewScreen.Height = info->header.h;
  206.         PlopNewScreen.Depth = info->header.nPlanes;
  207.         PlopNewScreen.ViewModes = 0;   /*start at default */
  208.         if (PlopNewScreen.Depth == 6)
  209.             PlopNewScreen.ViewModes |= HAM;
  210.         if (PlopNewScreen.Width > 320)
  211.             PlopNewScreen.ViewModes |= HIRES;
  212.         if (PlopNewScreen.Height > 200)
  213.             PlopNewScreen.ViewModes |= LACE;
  214.         if ( (PlopScreen = OpenScreen(&PlopNewScreen) ) == NULL)
  215.             {
  216. #ifdef PARANOID
  217.             printf("OpenScreen failed\n");
  218. #endif PARANOID        
  219.             printf("Not Enough Memory Available\n");
  220.             free_planes(&info->bitmap);
  221.             plop_cleanup();
  222.             return(-4);
  223.             }
  224.         MyWindow.Screen=PlopScreen;
  225.         if ((window = OpenWindow(&MyWindow)) == NULL)
  226.             {
  227. #ifdef PARANOID
  228.             printf("OpenWindow failed\n");
  229. #endif PARANOID
  230.             printf("Not Enough Memory Available\n");
  231.             free_planes(&info->bitmap);
  232.             plop_cleanup();
  233.             return(-5);
  234.             }
  235.         InitRastPort(&PlopRastPort);
  236.         PlopRastPort.Mask = (1<<PLANES)-1;  /*just play it safe in case someone
  237.                                             tries to load 6 bit planes...*/
  238.  
  239.         put_ea_cmap(&info->cmap, (1 << info->bitmap.Depth));
  240.         PlopRastPort.BitMap = &info->bitmap;
  241.         ClipBlit( &PlopRastPort, (long)0, (long)0,
  242.             &PlopScreen->RastPort, (long)info->header.x, (long)info->header.y,
  243.             (long)info->header.w, (long)info->header.h, (long)COPY_MINTERM);
  244.         
  245.         pdump(window);    /* printer dump */
  246.         for (;;) {
  247.             WaitPort(window->UserPort);
  248.             message = GetMsg(window->UserPort);
  249.             class=message->Class;
  250.             code=message->Code;
  251.             ReplyMsg(message);
  252.             switch(class){
  253.                 case CLOSEWINDOW:    CloseWindow(window);
  254.                             free_planes(&info->bitmap);
  255.                             plop_cleanup();
  256.                             return(0);
  257.                             break;
  258.  
  259.                 case MOUSEBUTTONS:    printf("Code = %d\n",code);
  260.                             CloseWindow(window);
  261.                             free_planes(&info->bitmap);
  262.                             plop_cleanup();
  263.                             return(0);
  264.                             break;        
  265.                 }
  266.             }
  267.         }
  268. #ifdef PARANOID
  269.     else
  270.         printf("Couldn't load %s as an IFF file\n",argv[i]);
  271. #endif PARANOID
  272.     }
  273. plop_cleanup();
  274. }
  275.  
  276.  
  277.